package cn.sjlink.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 通用结果返回
 */
public class Result {
    protected Logger log = LoggerFactory.getLogger(this.getClass());

    private int result;
    private String msg;
    private Object data;

    /**
     * 默认返回成功
     */
    public Result(){
        this(true, "");
    }

    /**
     * 按参数返回成功与否
     * @param success 是否成功
     */
    public Result(boolean success){
        this(success, "");
    }

    /**
     * 默认返回失败的result
     * @param msg 提示信息
     */
    public Result(String msg){
        this(false, msg);
    }

    /**
     * 按参数返回成功与否
     * @param success 是否成功
     * @param msg 提示信息
     */
    public Result(boolean success, String msg){
        this(success, msg, null);
    }

    /**
     * 默认返回成功
     * @param data 返回数据
     */
    public Result(Object data){
        this(true, "", data);
    }

    /**
     * 返回Result对象，由spring负责转换为JSON格式
     * @param success 是否成功
     * @param msg 提示信息
     * @param data 返回数据
     */
    public Result(boolean success, String msg, Object data){

        this(success ? ResultCode.SUCCESS : ResultCode.FAILURE, msg);
        if(null != data){
            this.data =data;
        }
    }

   /**
     * 由调用方法直接给result赋值
     * @param resultCode 结果代码，参照ResultCode
     * @param msg 提示信息
     */
    public Result(int resultCode, String msg){
        this.result = resultCode;
        this.msg = msg;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}


